package com.itheima.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class SortUtils {




    //先按长度排序,再按字母表排序
    public static List<String> sortByLenthAndValue(String[] str) {

        ArrayList<String> list4 = new ArrayList<>();
        ArrayList<String> list5 = new ArrayList<>();
        for (String s : str) {
            if (s.length()==4){
                list4.add(s);
            }else {
                list5.add(s);
            }
        }
        String[] arr4 = list4.toArray(new String[list4.size()]);
        String[] arr5 = list5.toArray(new String[list5.size()]);
        List<String> list44 = sort(arr4);
        List<String> list55 = sort(arr5);

        List arrList = new ArrayList(list44);

        for (String s : list55) {
            arrList.add(s);
        }
        return arrList;
    }

    //排序函数
    public static List<String> sort(String[] str) {
        for (int i = 0; i < str.length - 1; i++) {
            for (int j = i + 1; j < str.length; j++) {
                if (str[i].compareTo(str[j]) > 0)
                    swap(str, i, j);
            }
        }
        return Arrays.asList(str);
    }
    //交换函数
    public static void swap(String[] str,int i,int j) {
        String s=str[i];
        str[i]=str[j];
        str[j]=s;
    }
}
